
import json

from django.views.generic.base import View
from django.http.response import HttpResponse, JsonResponse
from django.core import serializers  # 专门做序列化

from goods.models import Goods
from django.forms.models import model_to_dict

class GoodsListView(View):
    """
    商品列表类视图
    """
    def get(self, request):
        """
        返回商品列表
        :param request:
        :return:
        """
        json_list = []

        goods = Goods.objects.all()[:10]

        json_data = serializers.serialize("json", goods)
        json_data = json.loads(json_data)

        return JsonResponse(json_data, safe=False)
